package com.source.module_kotlin_library.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.source.module_kotlin_library.R
import com.source.module_kotlin_library.bean.User

class KotlinMainActivity : AppCompatActivity(), View.OnClickListener {
    companion object {
        fun startActivity(context: Context) {
            val intent = Intent()
            intent.setClass(context, KotlinMainActivity::class.java)
            context.startActivity(intent)
        }
    }

    private val usernameKey = "username"
    private val passwordKey = "password"
    private lateinit var etUsername: EditText
    private lateinit var etPassword: EditText
    private lateinit var etVerifier: EditText
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_kotlin_main)
        etUsername = findViewById(R.id.etUsername)
        etPassword = findViewById(R.id.etPassword)
        etVerifier = findViewById(R.id.etVerifier)
        etUsername.setText("")
        var btnLogin: Button = findViewById(R.id.btnLogin)
        btnLogin.setOnClickListener(this)
    }

    override fun onClick(v: View) {
        if (v.id == R.id.btnLogin) {
            login()
        }
    }

    private fun login() {
        val username = etUsername.text.toString()
        val password = etPassword.text.toString()
        val verifyCode = etVerifier.text.toString()

        val user = User(username, password, verifyCode)
        if (verify(user)) {
            Toast.makeText(this, "校验成功", Toast.LENGTH_SHORT).show()
//            KotlinLessonActivity.startActivity(this@KotlinMainActivity)
//
//            KTLoginActivity.startActivity(this@KotlinMainActivity)
            KTDefineActivity.startActivity(this@KotlinMainActivity)
        }

    }

    private fun verify(user: User): Boolean {
        return true
    }
}